<template>
    <view style="height: 100%">
        <view v-if="coupons.length > 0" class="couponList">
            <view class="coupon_item" :data-item="item" @tap="showDetail" v-for="(item, i) in coupons" :key="i">
                <view class="top">
                    <view class="left_item algin">
                        <view class="money">
                            <text>￥</text>
                            <text class="num">{{ item.Ffacevalue }}</text>
                        </view>
                    </view>
                    <view class="center_item v-center">
                        <view class="text">消费满￥{{ item.Ffullvalue }}抵用</view>
                        <view class="date">{{ item.Fenddate }}天到期</view>
                    </view>
                    <view class="right_item v-center">
                        <image mode="widthFix" src="/static/file/images/passed.png"></image>
                    </view>
                </view>

                <view class="next">
                    {{ item.Fsummary }}
                </view>
            </view>
        </view>

        <view v-else class="blank">
            <view class="algin">
                <image mode="widthFix" class="noImg" src="/static/file/images/nolist.png"></image>
            </view>
            <view @tap="addAddress" class="no_msg algin">暂无失效劵</view>
        </view>
    </view>
</template>

<script>
// pages/myCoupon/myCoupon.js
var util = require('../../utils/util.js');
var api = require('../../utils/prom.js'); 
export default {
    data() {
        return {
            color: app.globalData.color,
            coupons: [],
            i: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that = this;
        var param = {};
        api.request('SpCouponUser?token=' + uni.getStorageSync('token') + '&status=0', 'get', param, function (res) {
            res.data.Rows.map(function (item) {
                var time = item.Fenddate.replace('T', ' ');
                var index = time.indexOf('.');
                if (index > 0) {
                    item.Fenddate = time.substr(0, index);
                } else {
                    item.Fenddate = time;
                }
            });
            that.coupons =  res.data.Rows;
        });
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {}, 
    methods: {
        showDetail() {
            console.log('占位：函数 showDetail 未声明');
        },

        addAddress() {
            console.log('占位：函数 addAddress 未声明');
        }
    }
};
</script>
<style>
@import './myCoupon.css';
</style>
